<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/4/11
 * Time: 下午9:43
 */

namespace App\Server;

use DB;

/**
 * 食物
 * Class FoodModel
 * @package App\Server
 */
class FoodModel extends BaseModel
{
    protected $table = 'food';

    public static $urls = [
        '0' => 'http://i3.meishichina.com/attachment/recipe/2016/08/05/20160805i7x8eia2092brtv5.jpg',
        '1' => 'http://i3.meishichina.com/attachment/recipe/2016/06/08/20160608urxaid518c3kcgc0.jpg',
        '2' => 'http://i3.meishichina.com/attachment/recipe/2016/06/03/20160603wlrd6t5pala6xvba.jpg',
        '3' => 'http://i3.meishichina.com/attachment/recipe/2016/06/03/20160603dqy2fe725ru13q14.jpg',
        '4' => 'http://i3.meishichina.com/attachment/recipe/2016/06/02/20160602az9t0c9gfliqjwvc.jpg',
        '5' => 'http://i3.meishichina.com/attachment/recipe/2016/05/26/20160526f4xteqkgazyy01xy.jpg',
        '6' => 'http://i3.meishichina.com/attachment/recipe/2016/05/22/2016052214639077122678851180.jpg',
        '7' => 'http://i3.meishichina.com/attachment/recipe/2016/04/29/2016042914619048411371918077.jpg',
        '8' => 'http://i3.meishichina.com/attachment/recipe/2016/04/24/20160424s2veg731ebevhniv.jpg',
        '9' => 'http://i3.meishichina.com/attachment/recipe/2016/04/24/20160424jlrcqr3qga29y2pr.JPG',
        '10' => 'http://i3.meishichina.com/attachment/recipe/2016/04/15/20160415q6u5hg2vdk2r2n83.jpg',
    ];

    /**
     * 分页获取列表
     *
     * @param int $pagesize
     * @param string $field
     * @param int $lastid
     * @param array $so
     * @return array
     */
    public static function getListLike($pagesize = 10, $field = '', $lastid = 1, $content = '', $type = 1)
    {
        $result = null;
        if ($content) {
            $so['title like'] = '%' . $content . '%';
            $result = self::where($so)->get();
        } else {
            $result = self::where()->orderBy('id', 'desc')->paginate($pagesize, $field, null, $lastid);
        }
        $_result = [];
        if ($result) {
            $data = [];
            foreach ($result as $k => $v) {
                $data[] = $v;
            }
            $_result['data'] = $data;
            $_result['total'] = $result->total();
            $_result['count'] = $result->count();
            $_result['currentPage'] = $result->currentPage();
            $_result['firstItem'] = $result->firstItem();
            $_result['lastItem'] = $result->lastItem();
//            $_result['hasMorePages'] = $result->hasMorePages();
            $_result['lastPage'] = $result->lastPage();
//            $_result['nextPageUrl'] = $result->nextPageUrl();
            $_result['perPage'] = $result->perPage();
//            $_result['previousPageUrl'] = $result->previousPageUrl();
            $_result['pagesize'] = $result->perPage();
        }

        return $_result;
    }

}